1.1 Creating a Stored Procedure
1 | create procedure dbo.spPeople_GetAll # use alter procedure for altering |
1.2 Calling a Stored Procedure
Direct call (e.g. select id, FirstName, LastName from dbo.People) has to be compiled then run, but a stored procedure is always compiled. It will be more efficient to call a stored procedure.
1 | exec dbo.spPeople_GetAll |
2.1 Creating a Stored Procedure to Sort by Last Name
1 | create procedure dbo.spPeople_GetByLastName |
2.2 Calling a Stored Procedure to Get People with Same Last Name
Last name was passed in as a variable
1 | exec dbo.spPeople_GetByLastName 'Corey' |
3.1 Creating a Stored Procedure to Sort by Last Name and First Name
1 | create procedure dbo.spPeople_GetByLastName |
3.2 Calling a Stored Procedure to Get People with Same Last Name and First Name
1 | exec dbo.spPeople_GetByLastName 'Corey','Tim' |